﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YAMN_Cinemas.Presentation
{
    public partial class U_MovieInfo : System.Web.UI.Page
    {
        public DateTime fromDate;
        public DateTime toDate;
        protected void Page_Load(object sender, EventArgs e)
        {
            
       
            TheatreEntities te=new TheatreEntities();
            cal_BookingDate.Visible = false;
            long movieID = Convert.ToInt64(Request.Params["movieID"]);
            Movy m = new Movy();
            var q = from x in te.Movies
                    where x.MovieID == movieID
                    select x;
            m = q.First();
            string imagename = m.Movie_Title;
            img_MoviePic.ImageUrl = "~/Images/"+imagename+".jpg";
            txt_MovieTitle.Text = m.Movie_Title.ToString();
            txt_Language.Text = m.Language;
            txt_Duration.Text = m.Duration;
            txt_Summary.Text = m.Summary;
            

        }

        protected void btn_Book_Click(object sender, EventArgs e)
        {
            TheatreEntities te = new TheatreEntities();
            string movieDate;
            long movieID = Convert.ToInt64(Request.Params["movieID"]);
            Movy m = new Movy();
            var q = from x in te.Movies
                    where x.MovieID == movieID
                    select x;
            m = q.First();
            movieDate = txt_BookingDate.Text;

            Response.Redirect(String.Format("http://localhost:6500/Presentation/SeatBooking1.aspx?screenID={0}&movieID={1}&STID={2}&movieDate={3}", Server.UrlEncode(m.ScreenID.ToString()), Server.UrlEncode(m.MovieID.ToString()), Server.UrlEncode(m.STID.ToString()), Server.UrlEncode(movieDate)));   
        }

        protected void imgbtn_Calendar_Click(object sender, ImageClickEventArgs e)
        {
            cal_BookingDate.Visible = true;
        }

        protected void cal_BookingDate_SelectionChanged(object sender, EventArgs e)
        {
            txt_BookingDate.Text = cal_BookingDate.SelectedDate.ToShortDateString();
            cal_BookingDate.Visible = false;
        }

        protected void cal_BookingDate_RenderChanged(object sender, DayRenderEventArgs e)
        {
            TheatreEntities te = new TheatreEntities();
            long movieID = Convert.ToInt64(Request.Params["movieID"]);
            Movy m = new Movy();
            var q = from x in te.Movies
                    where x.MovieID == movieID
                    select x;
            m = q.First();
            fromDate = m.FromDate;
            toDate = m.ToDate;
            if (e.Day.Date < fromDate)
            {
                e.Day.IsSelectable = false;
                e.Cell.ForeColor = System.Drawing.Color.Gray;

            }
            if (e.Day.Date > toDate)
            {
                e.Day.IsSelectable = false;
                e.Cell.ForeColor = System.Drawing.Color.Gray;
 
            }


        }
    }
}